﻿/*******************************************************************************

  NLocalizer (C) 2010-2012 Chris Prusik (KAP1 Ltd www.kap1.net)
  The fast, simple solution for localizing .NET applications, by text files.
  Latest version: http://NLocalizer.codeplex.com/

  $Id$

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

*******************************************************************************/
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NLocalizer.Tests
{
    [TestClass]
    public class MacroTest
    {
        [TestMethod]
        public void GetMacrosTest()
        {
            List<string> macros = Macro.GetMacros("$(FirstMacro)adjdhas khkladas$(SecondMacro)dasdsdasdas$(ThirdMacro)");
            Assert.AreEqual(3, macros.Count);
            Assert.AreEqual("FirstMacro", macros[0]);
            Assert.AreEqual("SecondMacro", macros[1]);
            Assert.AreEqual("ThirdMacro", macros[2]);

            macros = Macro.GetMacros("$(FirstMacro())adjdhas khkladas$(SecondMacro((111)222))dasdsdasdas$(ThirdMacro((())))");
            Assert.AreEqual(3, macros.Count);
            Assert.AreEqual("FirstMacro()", macros[0]);
            Assert.AreEqual("SecondMacro((111)222)", macros[1]);
            Assert.AreEqual("ThirdMacro((()))", macros[2]);
        }

        [TestMethod]
        public void ToNumbersNamesTest()
        {
            string message = "$(FirstMacro)adjdhas khkladas$(SecondMacro)dasdsdasdas$(ThirdMacro)";
            Assert.AreEqual(message.Replace("FirstMacro", "1").Replace("SecondMacro", "2").Replace("ThirdMacro", "3"),
                Macro.NamesToNumbers(message));
            List<string> macros = Macro.GetMacros(message);
            Assert.AreEqual(message, Macro.NumbersToNames(Macro.NamesToNumbers(message, macros), macros));

            message = "$(FirstMacro())adjdhas khkladas$(SecondMacro((111)222))dasdsdasdas$(ThirdMacro((())))";
            Assert.AreEqual(message.Replace("FirstMacro()", "1").Replace("SecondMacro((111)222)", "2").Replace("ThirdMacro((()))", "3"),
                Macro.NamesToNumbers(message));
            macros = Macro.GetMacros(message);
            Assert.AreEqual(message, Macro.NumbersToNames(Macro.NamesToNumbers(message, macros), macros));

            message = "$(Application.ProductName + \"-\" + Application.ProductVersion)";
            Assert.AreEqual("$(1)", Macro.NamesToNumbers(message));
            macros = Macro.GetMacros(message);
            Assert.AreEqual(message, Macro.NumbersToNames(Macro.NamesToNumbers(message, macros), macros));
        }
    }
}
